Skip to main content

edexaJS ERC721 tutorial

· 3 min read
Max Meinhardt

This tutorial will guide you through the process of deploying and interact an ERC-721 contract using the edexaJS library.

Prerequisite

  1. Getting Faucet: Before deploying an ERC-721 contract, you'll need testnet EDX coin to cover transaction costs. You can use a faucet to obtain test EDX Coin for the edexa network. Faucet Link
  1. Node Version: Ensure that your Node.js version is greater than 16.

2. Obtaining Private Key

To interact with the edexa network, you'll need a private key. Here's how you can obtain one:

  • Using Wallets like Metamask

    1. Open your preferred Ethereum wallet, such as Metamask or Trust Wallet.
    2. Navigate to the account settings or account details section.
    3. Look for an option like "Export Private Key" or "View Private Key."
    4. Copy the private key to your clipboard.

    Note: Ensure that the account from which you are obtaining the private key is associated with the edexa network

    Important: Never share your private key publicly, and handle it with the utmost care. It's recommended to use a separate account or wallet for testing purposes.

3. Installing the edexaJS Package

Use npm to install the edexaJS package:

npm install @edexa/edexajs

4. Creating Signer using edexaJS

In your code, import the EdexaClient and create a signer with your private key:

import { EdexaClient } from "@edexa/edexajs";

const edexaClient = new EdexaClient();
const privateKey = "your actual private key here"; // Always handle with care!
const signer = edexaClient.createWalletSigner(privateKey);

5. Deploying ERC-721 Contract

Use the createContractERC721 function to deploy an ERC-721 contract. It returns the newly deployed contract address:

async function deployERC721Contract() {
const erc721Arg = {
name: "YourTokenName",
symbol: "YTN",
};

const erc721Contract = await edexaClient.createContractERC721(
erc721Arg,
signer
);
contractAddress = erc721Contract.address;
}

6. Interacting with the Deployed Contract

To interact with the deployed ERC-721 contract, use the getERC721Instance function to obtain an instance. Then, use various functions like getBalance:

// pass the contractAddress that we got from previous point
const erc721 = edexaClient.getERC721Instance(contractAddress);

const address = "Address you want to find balance off";
const balance = await erc721.getBalance(address);

You can find the code sample here

Refer to the edexaJS documentation for more functions and details.